/*
 * SampleGrabberCallback.h
 *
 *  Created on: 2011-8-7
 *      Author: terry
 */

#ifndef SAMPLEGRABBERCALLBACK_H_
#define SAMPLEGRABBERCALLBACK_H_


#include "SampleCallBack.h"
#include "Unknown.h"
#include "DShowType.h"



class VideoGrabberCallback : public TUnknown<ISampleGrabberCB>
{
public:
    explicit VideoGrabberCallback(av::SampleCallBack* pOnwer):
        m_pOnwer(pOnwer)
    {
    }

    virtual ~VideoGrabberCallback()
    {
    }

    virtual HRESULT STDMETHODCALLTYPE BufferCB(double SampleTime, BYTE *pBuffer,long BufferLen)
    {
		if (!m_pOnwer)
		{
			return S_OK;
		}
        return m_pOnwer->onVideoSample(SampleTime, pBuffer, BufferLen);
    }

    virtual HRESULT STDMETHODCALLTYPE SampleCB(double SampleTime, IMediaSample *pSample)
    {
		if (!m_pOnwer)
		{
			return S_OK;
		}

        BYTE* pBuffer = NULL;
        pSample->GetPointer(&pBuffer);
        long bufferLength = pSample->GetActualDataLength();
        return m_pOnwer->onVideoSample(SampleTime, pBuffer, bufferLength);
    }

protected:
    av::SampleCallBack*  m_pOnwer;
};


class AudioGrabberCallback : public TUnknown<ISampleGrabberCB>
{
public:
    explicit AudioGrabberCallback(av::SampleCallBack* pOnwer) :
        m_pOnwer(pOnwer)
    {
    }

    virtual ~AudioGrabberCallback()
    {
    }

    virtual HRESULT  STDMETHODCALLTYPE BufferCB(double SampleTime, BYTE *pBuffer,long BufferLen)
    {
        return m_pOnwer->onAudioSample(SampleTime, pBuffer, BufferLen);
    }

    virtual HRESULT  STDMETHODCALLTYPE SampleCB(double SampleTime, IMediaSample *pSample)
    {
        BYTE* pBuffer = NULL;
        pSample->GetPointer(&pBuffer);
        long bufferLength = pSample->GetActualDataLength();
        return m_pOnwer->onAudioSample(SampleTime, pBuffer, bufferLength);
    }

protected:
    av::SampleCallBack*  m_pOnwer;
};







#endif /* SAMPLEGRABBERCALLBACK_H_ */
